package com.chase.framerwork.service;

import java.io.Serializable;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Order;
import org.springframework.transaction.annotation.Transactional;

import com.chase.framerwork.bean.Pager;
import com.chase.framerwork.dao.BaseDao;

/**
 * Service层最父类,所有Service都必须继承自该父类
 * 
 * @author Chase
 * 
 * @param <E>
 *            Entity
 * @param <ID>
 *            ID
 */
@Transactional
public class BaseServiceImpl<E, ID extends Serializable> implements BaseService<E, ID>
{

	private BaseDao<E, ID> baseDao;

	@Override
	@Transactional(readOnly = true)
	public E get(ID id)
	{
		return baseDao.get(id);
	}

	@Override
	@Transactional(readOnly = true)
	public E load(ID id)
	{
		return baseDao.load(id);
	}

	@Override
	@Transactional(readOnly = true)
	public List<E> getAllList()
	{
		return baseDao.getAllList();
	}

	@Override
	@Transactional(readOnly = true)
	public Long getTotalCount()
	{
		return baseDao.getTotalCount();
	}

	@Override
	@Transactional
	public ID save(E entity)
	{
		return baseDao.save(entity);
	}

	@Override
	@Transactional
	public void save(List<E> userList)
	{
		for (E entity : userList)
		{
			save(entity);
		}
	}

	@Override
	@Transactional
	public void update(E entity)
	{
		baseDao.update(entity);
	}

	@Override
	@Transactional
	public void delete(E entity)
	{
		baseDao.delete(entity);
	}

	@Override
	@Transactional
	public void delete(ID id)
	{
		baseDao.delete(id);
	}

	@Override
	@Transactional
	public void delete(ID[] ids)
	{
		baseDao.delete(ids);
	}

	@Override
	@Transactional(readOnly = true)
	public void flush()
	{
		baseDao.flush();
	}

	@Override
	@Transactional(readOnly = true)
	public void evict(Object object)
	{
		baseDao.evict(object);
	}

	@Override
	@Transactional(readOnly = true)
	public void clear()
	{
		baseDao.clear();
	}

	@Override
	@Transactional(readOnly = true)
	public Pager findPager(Pager pager)
	{
		return baseDao.findPager(pager);
	}

	@Override
	@Transactional(readOnly = true)
	public Pager findPager(Pager pager, Criterion... criterions)
	{
		return baseDao.findPager(pager, criterions);
	}

	@Override
	@Transactional(readOnly = true)
	public Pager findPager(Pager pager, Order... orders)
	{
		return baseDao.findPager(pager, orders);
	}

	@Override
	@Transactional(readOnly = true)
	public Pager findPager(Pager pager, Criteria criteria)
	{
		return baseDao.findPager(pager, criteria);
	}

	public BaseDao<E, ID> getBaseDao()
	{
		return baseDao;
	}

	public void setBaseDao(BaseDao<E, ID> baseDao)
	{
		this.baseDao = baseDao;
	}
}